package com.gis.servlet.find;

import com.gis.bean.Find;
import com.gis.dao.FindDao;
import com.gis.util.Constant;
import com.gis.util.ResponseUtil;
import com.gis.util.RestResponse;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author t-zhaoheng
 * @since 2022/5/16
 */
@WebServlet("/find/get.do")
public class FindGetServlet extends HttpServlet{
  private static final long serialVersionUID = 1L;

  /**
   * @see HttpServlet#HttpServlet()
   */
  public FindGetServlet() {
    super();
    // TODO Auto-generated constructor stub
  }

  /**
   * @see HttpServlet #doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String id = request.getParameter("id");
    Find find = FindDao.getInstance().getFind(Integer.parseInt(id));
    if (find == null) {
      ResponseUtil.writeJson(response, RestResponse.fail(Constant.OBJECT_NOT_EXIST));
      return;
    }
    ResponseUtil.writeJson(response, RestResponse.success(find));
  }

  /**
   * @see HttpServlet #doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
  }
}
